<template>
  <div ref="mainCon" class="container">
    <topTitle v-if="!hiddleToolBar" :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="tipBar2">
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/declarePro.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>1.添加劳资信息</div>
            <span class="fontCss">劳资专管员岗位证书由监察考核通过后发放</span>
          </div>
        </el-col>
        <el-col class="stepCss">
          <img src="../../../static/img/salary/stepLine.png" class="lineCss" />
        </el-col>
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/auditReport.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>2.等待审核</div>
            <span class="fontCss">等待当地监管部门审核提交的内容</span>
          </div>
        </el-col>
        <el-col class="stepCss">
          <img src="../../../static/img/salary/stepLine.png" class="lineCss" />
        </el-col>
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/approved.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>
              3.审核通过
              <span class="fontCss"
                >审核通过后即可在花名册查看劳资专管员资质信息</span
              >
            </div>
          </div>
        </el-col>
      </el-row>
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="人员姓名" class="row-padding-bottom">
              <el-input
                placeholder="请输入姓名或身份证号"
                clearable
                v-model="filterField.keyword"
                @blur="filterField.keyword = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="证书编号" class="row-padding-bottom">
              <el-input
                placeholder="请输入证书编号"
                clearable
                v-model="filterField.certificateNumber"
                @blur="filterField.certificateNumber = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="审核状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.auditStatus"
                  filterable
                  placeholder="请选择"
                  clearable
                  :popper-append-to-body="false"
                >
                  <el-option
                    v-for="item in statusOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
              <!-- <el-button class="commonBut saveBtn funComBut" icon="icon iconfont icontianjia" v-sdc @click="toAddLabor">
                                <span class="opetareText">添加劳资资质</span>
                            </el-button> -->
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <div style="margin-bottom: 24px">
          <el-button
            class="commonBut saveBtn funComBut"
            icon="icon iconfont icontianjia"
            v-sdc
            @click="toAddLabor"
          >
            <span class="opetareText">添加劳资资质</span>
          </el-button>
        </div>
        <!-- 列表 -->
        <el-table
          ref="tableBox1"
          @sort-change="sortChange"
          :max-height="tableHeight"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column align="center" prop="imgPath" label="身份证照片">
            <template slot-scope="scope">
              <el-image
                v-if="scope.row.imgPath"
                style="width: 50px; height: 50px; top: 3.5px"
                :src="scope.row.imgPath"
                :preview-src-list="scope.row.idcardImgList"
              >
              </el-image>
              <el-image
                v-else
                src="../../../static/img/employee/card.png"
                alt=""
                style="width: 50px; height: 50px; top: 3.5px"
              />
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="name"
            label="姓名"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="idcard"
            label="身份证号"
            min-width="120"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.idcard | deseHandler(4, 4, '*') || '--' }}</p>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="certificateNumber"
            label="证书编号"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="sexValue"
            label="性别"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="nationalityValue"
            label="民族"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            align="center"
            sortable="custom"
            prop="createTime"
            label="录入时间"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="auditStatusStr"
            label="审核状态"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column align="left" label="操作" fixed="right" width="80px">
            <template slot-scope="scope">
              <el-link type="primary" @click="toDetail(scope.row)"
                >查看</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :requestUrl="requestUrl"
          :filterField="filterField"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
import { mapActions, mapState } from 'vuex'

export default {
  name: 'laborInfoCz',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '劳资信息',
      advanced: false,
      statusOptions: [
        { name: '待审核', id: '0' },
        { name: '已通过', id: '1' },
        { name: '已驳回', id: '2' },
      ], //审核状态
      //表格数据
      tableData: [],
      requestUrl: 'api-e/cs/qualification/expand/list',
      idcardImgList: [],
      //搜索条件
      filterField: {
        keyword: '',
        certificateNumber: '',
        auditStatus: '',
      },
      isShow: false, //列表加载
      loading: true,
      isShowDetail: '',
    }
  },
  created() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.getStatus()
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      } else {
        this.idcardImgList = []
        for (var i = 0; i < this.tableData.length; i++) {
          this.idcardImgList.push(this.tableData[i].imgPath)
        }
        for (var i = 0; i < this.tableData.length; i++) {
          var container = this.idcardImgList
          var frontArr = container.slice(0, i)
          var behindArr = container.slice(i, this.tableData.length)
          var list = behindArr.concat(frontArr)
          this.tableData[i].idcardImgList = list
        }
      }
    },
    getStatus() {
      this.axios({
        method: 'post',
        url: 'api-p/projectapplication/expand/status',
        data: {},
      })
        .then((response) => {
          // this.statusOptions = response.data.result;
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取审核状态数据失败',
            type: 'error',
          })
        })
    },
    // 搜索
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    toDetail(row) {
      this.$router.push({
        path: '/home/employee/laborAuditDetailCz',
        name: 'laborAuditDetailCz',
        query: {
          id: row.id,
          path: 'laborInfoCz',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/employee/laborInfoCz',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    toAddLabor() {
      this.axios({
        method: 'post',
        url: 'api-e/cs/contract/expand/detailbyworkertype',
        data: {
          type: '60', //劳资专管员
        },
      })
        .then((response) => {
          if (!response.data.hasError) {
            if (
              !response.data.hasError &&
              response.data.result.list.length > 0
            ) {
              this.$router.push({
                path: '/home/employee/laborInfoAddCz',
                name: 'laborInfoAddCz',
              })
              this.$store.commit('CHANGE_SLIDER_NAME', {
                oldUrl: '/home/employee/laborInfoCz',
                newUrl: this.$router.currentRoute.fullPath,
              })
            } else {
              this.$message({
                message: '项目暂未录入劳资专管员，请先录入劳资专管员',
                type: 'warning',
              })
              return
            }
          }
        })
        .catch((error) => {})
    },
  },
}
</script>

<style lang="less" scoped>
.tipBar2 {
  height: 88px;
  margin: 16px 20px 35px 20px;
}
.hint {
  float: left;
  display: block;
  width: 24%;
  padding-left: 5%;
}
.imgLabel {
  display: inline-block;
  float: left;
}
.picCss {
  color: #d0d0d8;
}
.lineCss {
  width: 100%;
  height: 8px;
  margin-top: 40px;
}
.stepCss {
  float: left;
  display: block;
  width: 12%;
}
.hintCss {
  display: block;
  margin-left: 85px;
  margin-top: 15px;
}
.fontCss {
  font-size: 14px;
  color: #666;
  display: block;
}
@media screen and (min-width: 1280px) and (max-width: 1366px) {
  .searchInputWidth /deep/ .el-form-item__label {
    width: 70px;
  }
}
@import '../../../static/css/filterArea.less';
</style>
